home *** CD-ROM | disk | FTP | other *** search
/ Biodiversity of Illinois 2: Woodland Habitats / Biodiversity of Illinois 2 - Woodland Habitats.iso / mac / casts / PDFxtraBehaviors.cst / 00002_Script_PDF_Open with defaults < prev    next >
Text File  |  2006-07-11  |  8KB  |  203 lines

  1. -- Open
  2.  
  3. Property pEvent, pSprite, pMemberName, pPathType, pEnableUpdateFromURL, pUpdateFromURL, pAlertFlag
  4.  
  5. on doOpen me
  6.   
  7.   -- get the pathname from the text member
  8.   myMember = me.ExtractMemberFromString(pMemberName)[2]
  9.   f = myMember.text
  10.   
  11.   if (f="") then exit
  12.   set err = PDF_Open(sprite pSprite, f, [#pathtype: pPathType, #EnableUpdateFromURL: pEnableUpdateFromURL, #UpdateFromURL: pUpdateFromURL, #DisplayOption: #documentdisplayoptions])
  13.   if PDF_status(sprite pSprite) then alert "PDF Behavior Error"&RETURN&PDF_error(sprite pSprite)
  14. end doOpen
  15.  
  16. on mouseUp me
  17.   if (pEvent = #mouseUp) then doOpen(me)
  18. end mouseUp
  19.  
  20. on mouseDown me
  21.   if (pEvent = #mouseDown) then doOpen(me)
  22. end mouseDown
  23.  
  24. on prepareFrame me
  25.   if (pEvent = #prepareFrame) then doOpen(me)
  26. end prepareFrame
  27.  
  28. on beginsprite me
  29.   if (pEvent = #beginsprite) then doOpen(me)
  30. end beginsprite
  31.  
  32. -- standard behavior stuff --
  33. on getPropertyDescriptionList me
  34.   set defaultValues = GetDefaultValues (me)
  35.   
  36.   set pdfSpriteList = getProp (defaultValues, #spriteList)
  37.   set defSprite     = getProp (defaultValues, #defaultSprite)
  38.   if (defSprite=0) then 
  39.     if the ticks - pAlertFlag > 10 then
  40.       alert "Please create a sprite of type PDF first."
  41.     end if
  42.     set pAlertFlag = the ticks -- The ticks when the user clicked "OK"
  43.     
  44.     exit
  45.   end if
  46.   
  47.   -- retrieve all members of type text, field or Flashcomponent
  48.   lTextFields = me.GetMembers([#text, #field, #flashcomponent])
  49.   if (lTextFields = []) then
  50.     alert "You need at least one member of type #field or #text to use this behavior."
  51.     exit
  52.   end if 
  53.   
  54.  
  55.   set p_list = [:]
  56.   addprop p_list, #pEvent,[ #comment: "Event", #format:#symbol, #range:[#mouseUp, #mouseDown, #prepareFrame, #beginsprite], #default:#mouseUp]
  57.   addprop p_list,#pSprite, [ #comment: "PDF Sprite is in channel:", #format:#symbol, #range:pdfSpriteList, #default:defSprite]
  58.   if (lTextFields.count = 0) then
  59.     addprop p_list, #pMemberName, [ #comment: "File name is in member::", #format: #string, #default:"<no named fields or text members available>"]
  60.   else  
  61.     addprop p_list, #pMemberName, [ #comment: "File name is in member::", #format:#member, #default:lTextFields[1], #range:lTextFields]
  62.   end if
  63.   addprop p_list,#pPathType, [ #comment: "Path is:", #format: #symbol,#range: [ "Absolute or URL", "Relative to Movie", "Relative to Playback Engine" ],#default: "Absolute or URL" ]
  64.   addprop p_list,#pEnableUpdateFromURL,[ #comment: "Enable update URL:", #format:#boolean, #default:FALSE ]
  65.   addprop p_list,#pUpdateFromURL, [ #comment: "Update URL (if enabled):", #format:#string, #default:"http://" ]
  66.   return p_list
  67. end
  68.  
  69. on getBehaviorTooltip
  70.   return "Link the PDF document, whose name is specified in a Director field," & RETURN& "to the designated PDF Xtra sprite. Show/hide toolbars." & RETURN& "All platforms."
  71. end
  72. on getBehaviorDescription
  73.   tmp = "Link the PDF document whose name is specified in a Director field to the designated PDF Xtra sprite. If the designated sprite is already linked to a PDF document, that document is first closed and then the new one opened." & RETURN& "All platforms."
  74.   tmp = tmp &RETURN&RETURN& "--- PARAMETERS --- "   
  75.   tmp = tmp &RETURN& " - Event: mouseUp, mouseDown, prepareFrame, or beginSpritePDF"
  76.   tmp = tmp &RETURN& " - Sprite is in channel: which channel contains the PDF Sprite"
  77.   tmp = tmp & RETURN& " - File name is in field: the field cast member that contains the name of the PDF document to open."
  78.   tmp = tmp & RETURN& " - Path is: Absolute or URL, Relative to Movie, Relative to Playback Engine."
  79.   tmp = tmp & RETURN& " - Enable update URL: If this box is checked, there must be a valid URL in the Update URL field."
  80.   tmp = tmp & RETURN& " - Update URL: The URL containing the PDF document to download if the local one is older."
  81.   tmp = tmp & RETURN& " - Start at page: Which page of the document should be displayed on opening."
  82.   tmp = tmp & RETURN& " - Start at zoom: Fit Width, Actual Size, Fit Page, Other."
  83.   tmp = tmp & RETURN& " - Other zoom (8..1600): A number representing the percentage to scale the document."
  84.   tmp = tmp & RETURN& " - Display mode: Pages Only, Bookmark And Pages, or Thumbnail And Pages"
  85.   tmp = tmp & RETURN& " - Show Toolbar: Display toolbar if checked (to show the toolbar in Director, the PDF document must have been saved in Acrobat, with the toolbar showing); hide the toolbar otherwise."
  86.   tmp = tmp & RETURN& " - Show Scrollbars: Display scrollbars if checked; hide scrollbars otherwise." & RETURN & " - Scroll H: Set the horizontal scroll position to the number of pixels specified."
  87.   tmp = tmp & RETURN& " - Scroll V: Set the vertical scroll position to the number of pixels specified."
  88.   tmp = tmp &RETURN&RETURN& "Free to use and abuse. (c)1999-2005, Integration New Media, Inc." &RETURN& "Thanks to James Newton for his suggestions."  
  89.   return tmp 
  90. end
  91.  
  92. -- utils --
  93. on GetDefaultValues me
  94.   if the currentSpriteNum then
  95.     set spriteList = GetSpriteList (me #PDF)
  96.     if count (spriteList) then
  97.       set defaultSprite = getAt (spriteList, 1)
  98.     else
  99.       set defaultSprite = 0
  100.     end if
  101.     
  102.     return [#spriteList: spriteList, #defaultSprite: defaultSprite]
  103.     
  104.   else -- the currentSpriteNum = 0
  105.     -- Director is merely recompiling this script: return dummy values
  106.     return [#spriteList: [1], #defaultSprite: 1]
  107.   end if
  108. end 
  109.  
  110. on GetSpriteList me, memberType
  111.   -- return list of sprites of type memberType in current frame
  112.   global version
  113.   if (char 1 of version = 6) then
  114.     set maxSprite = 120
  115.   else
  116.     set maxSprite = the lastChannel
  117.   end if
  118.   
  119.   set aList=[]
  120.   
  121.   repeat with i = 1 to maxSprite
  122.     set spriteMember = the member of sprite i
  123.     -- if (string(m) contains "member 0") then next repeat -- unnecessary
  124.     if (the type of spriteMember = memberType) then -- (JN) Line break
  125.       append (aList, i)
  126.     end if
  127.   end repeat
  128.   
  129.   return aList
  130. end GetSpriteList
  131.  
  132.  
  133. on GetMembers me, theMembersTypeNeeded  
  134.   
  135.   lResult = []
  136.   
  137.   lCastLib = the number of castLibs
  138.   
  139.   repeat while lCastLib -- repeat through all linked castlibs
  140.     
  141.     lMemberNum = the number of members of castLib(lCastLib)
  142.     
  143.     repeat while lMemberNum -- repeat through all members of the current castlib
  144.       lMemberType = member(lMemberNum, lCastLib).type
  145.       
  146.       if (theMembersTypeNeeded.getOne(lMemberType) > 0) then -- check if the member's type is contained in theMembersTypeNeeded
  147.         lName = member(lMemberNum, lCastLib).name 
  148.         if (lName <> "") then 
  149.           
  150.           lResult.AddAt(1, lName&&"(member"&&lMemberNum&&"of castlib"&&lCastLib&")") -- Add the member to the list
  151.         end if
  152.       end if
  153.       
  154.       set lMemberNum = lMemberNum - 1 -- check the next member
  155.     end repeat
  156.     
  157.     set lCastLib = lCastLib - 1 -- check the next castlib
  158.   end repeat
  159.   
  160.   return lResult
  161. end GetMembers
  162.  
  163. --
  164. -- Extract name and reference to a member contained in a string
  165. --    in a list [<name>, <(member xxx of castlib yyy)>]
  166. -- the String contains a reference to a member formatted like
  167. --    "<member name> (member xxx of castlib yyy)"
  168. --
  169. on ExtractMemberFromString me, theString
  170.   lResult = ["", VOID]
  171.   
  172.   if (StringP(theString)) then -- check if theString contains a string
  173.     lPos = offset("(member ", theString) -- find the offset of the substring "(member "
  174.     if (lPos > 0) then -- substring found = theString is a valid member reference
  175.       lName= ""
  176.       
  177.       if (lPos > 2) then
  178.         lName = theString.char[1..lPos-2]
  179.         if (lName) = "<no name>" then
  180.           lName = ""
  181.         end if
  182.       end if
  183.       
  184.       lMember = value(theString.char[lPos..theString.chars.count])
  185.       -- check if the member name and member reference are consistent
  186.       if (lMember <> VOID) then
  187.         if (lMember.name <> lName) then -- the user probably moved the cast member, we'll try to find it
  188.           if (lName <> "") then -- the member didn't have a name, so it's useless to look for it
  189.             lMember = member(lName)
  190.           else
  191.             lMember = VOID
  192.           end if
  193.         end if
  194.       end if
  195.       
  196.       lResult = [lName, lMember]
  197.     end if
  198.   end if
  199.   
  200.   return lResult
  201. end ExtractMemberFromString
  202.  
  203.